package com.chixing.day08_interface;

/**
 * 把 A  implements Comparable<T>比较两个对象的先后顺序
 *      实现了自然顺序
 *
 *      TreeMap ，TreeSet
 *
 */
public class Product implements Comparable<Product>{
    private String proName;
    private int proSale;
    private float proPrice;

    public Product(){}
    public Product(String proName, int proSale, float proPrice) {
        this.proName = proName;
        this.proSale = proSale;
        this.proPrice = proPrice;


    }

    @Override
    public int compareTo(Product anotherProduct) {
        if (this.proSale!= anotherProduct.proSale)
            return this.proSale - anotherProduct.proSale;
        else if (this.proPrice!= anotherProduct.proPrice)
            return (int) (this.proPrice- anotherProduct.proPrice);
        else
            return this.proName.compareTo(anotherProduct.proName);
    }
}

